package com.hdq.controller.admin;

import com.hdq.result.Result;
import com.hdq.service.RuleService;
import dto.RuleAddDTO;
import dto.RuleEditDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vo.RoleXiaLaListVO;
import vo.RuleInfoVO;

import java.util.List;

@RestController
@RequestMapping("/admin/rule")
@Tag(name = "权限管理")
public class RuleController {

    @Autowired
    private RuleService ruleService;

    @GetMapping
    @Operation(summary = "查询权限列表")
    public Result<List<RuleInfoVO>> select() {
        List<RuleInfoVO> list = ruleService.select();
        return Result.success(list);
    }

    @PostMapping
    @Operation(summary = "新增权限")
    public Result insert(@RequestBody RuleAddDTO ruleAddDTO) {
        ruleService.insert(ruleAddDTO);
        return Result.success();
    }


    @DeleteMapping("/{id}")
    @Operation(summary = "删除权限")
    public Result delete(@PathVariable Long id){
        ruleService.delete(id);
        return Result.success();
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改权限")
    public Result update(@PathVariable Long id, @RequestBody RuleEditDTO ruleEditDTO){
        ruleService.update(id,ruleEditDTO);
        return Result.success();
    }

}
